package com.sw.core.memcache;

import java.util.Iterator;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.sw.core.memcache.bean.MemcacheBean;
import com.tapestry.app.core.data.IList;
import com.tapestry.app.core.data.dataimp.DataList;

public class InitMemcache extends HttpServlet implements ServletContextListener{
	
	protected static Logger log = Logger.getLogger(InitMemcache.class);
	
	public void init() {
		try {
			super.init();
			log.info("==================memcache加载开始======================");
			MemcacheBean bean = new MemcacheBean();
			IList list = new DataList();
			list = bean.queryMemcacheInfo(null);
			MemCache.memcache_set(list);
			
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	
	
	public IList getCacheInfo() throws DocumentException{
		
		IList list = new DataList();
		String result = "";
		Document document = DocumentHelper.parseText(result);
		Element rootElement = document.getRootElement();
		
		
		for(Iterator itor = rootElement.elementIterator() ; itor.hasNext();){
			
			Element element = (Element) itor.next();
			
			
		}
		
		return list;
		
	}
	

}
